<?php

/**
 * @copyright   FOSP
 * @version     20120407
 * @todo        Report Type model
 * @name        ReportType
 * @author      QuangTM 
 */
class ReportType
{
    
    const ALL_REPORT = 'report_type_all';

    /**
     *
     * @var ReportType
     */
    protected static $instance;

    protected function __construct()
    {
        
    }

    /**
     * Get ReportType's instance
     * @return ReportType
     * @author QuangTM
     */
    public static function getInstance()
    {
        if (!isset(self::$instance) || !self::$instance instanceof self)
            self::$instance = new self;
        return self::$instance;
    }
    
    public function getAllReportType()
    {
        $memcacheInstance = Fpt_Global::getMemcacheInstance(1);
        $keyCache         = Fpt_Global::makeCacheKey(self::ALL_REPORT);
        
        // Read cache
        $arrReportType = $memcacheInstance->read($keyCache);
        
        // Miss cache
        if ($arrReportType === FALSE)
        {
            try
            {
                $config   = Fpt_Global::getApplicationIni();
                // Get db teamseason instance
                $reportTypeObj = Fpt_Business_ReportType::factory($config['database']['default']);

                // Get data from db
                $arrReportType = $reportTypeObj->getAllReportType();

                // Write to cache
                if (count($arrReportType))
                    Fpt_Global::writeMemcache(1, $keyCache, $arrReportType);
                else
                    Fpt_Global::writeMemcache(1, $keyCache, -1);
            }
            catch (Exception $ex)
            {
                Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
                return FALSE;
            }
        }
        else if($arrReportType == -1)
        {
            return array();
        }
        
        return $arrReportType;
    }

}